% note that the dead states do not enter the welfare
% calculation --> i am just adding the states that 
% are alive 

function [CE, share_floor] = Welfare_4_crra(Wi,Ppaid,oop,sigma,iX,rho,Nstates,floor)
    T = size(Ppaid,1);
    C = Wi-Ppaid-oop;
    share_floor= mean(mean(C<floor));
    C(C<floor)=floor;
    u = 1/(1-sigma)*(1000*C).^(1-sigma);
    Num = mean(sum(u.*(iX~=(Nstates+1)).*power(rho,(1:T)-1)',1));
    Den = mean(sum((iX~=(Nstates+1)).*power(rho,(1:T)-1)',1));
    CE  = ((1-sigma)*(Num/Den))^(1/(1-sigma));
end